<template>
  <BasicModal title="合并支付 - 数据提交" @register="registerModal"
              :canFullscreen="false" :centered="true"
              :width="400" :height="260"
              :bodyStyle="{ padding:'0px' }"
              :cancelButtonProps="{ disabled: loading }"
              :okButtonProps="{ loading: loading }"
              @ok="handleSubmit"
  >
    <table id="businessAddFrom" cellpadding="0" cellspacing="1" class="formtable" style="font-size: 14px">
      <tr>
        <td align="right" width="80" class="enforcetd_bg"><label class="Validform_label"> 单位名称:</label></td>
        <td align="left" class="value">{{accountFlow.dwmc}}</td>
      </tr>
      <tr>
        <td align="right" width="80" class="enforcetd_bg"><label class="Validform_label"> 收支笔数:</label></td>
        <td align="left" class="value">{{accountFlow.counts}}</td>
      </tr>
      <tr>
        <td align="right" width="80" class="enforcetd_bg"><label class="Validform_label"> 付款金额:</label></td>
        <td align="left" class="value text-green-500">{{accountFlow.je}}</td>
      </tr>
      <a-input type="hidden" id="account_ids" name="account_ids" v-model:value="accountFlow.ids" />
      <a-input type="hidden" id="account_sflx" name="sflx" v-model:value="accountFlow.sflx" />
    </table>
  </BasicModal>
</template>
<script lang="ts" setup>
import "/@/design/tablefrom.css";
import { ref, computed, unref, onMounted, reactive } from "vue";
import { paymentSelect, paymentSubmit } from "../types/accountBatch.api";
import { BasicModal, useModalInner } from "/@/components/Modal";
import { object } from "vue-types";
import { useMessage } from "/@/hooks/web/useMessage";
import { count } from "console";
import { result } from "lodash-es";

const { createMessage: $message } = useMessage();
// 声明Emits
const emit = defineEmits(['success', 'register']);

let loading = ref<boolean>(false);
let accountFlow = reactive({
  ids: '',
  dwmc: '',
  je: '',
  sflx: '',
  counts: 0
});

//表单赋值
const [registerModal, {setModalProps, closeModal}] = useModalInner(async (data) => {
  //重置表单
  //await resetFields();
  //setModalProps({confirmLoading: false});
  loading.value = false
  paymentSelect({ids: data.ids}).then((res) => {
    Object.assign(accountFlow, res)
  })
});

//表单提交事件
async function handleSubmit() {
  try {
    //setModalProps({confirmLoading: true});
    loading.value = true
    paymentSubmit(accountFlow).then((res) => {
      //console.info("ajaxAccountOnTrustRefer@", res)
      loading.value = false
      if (res.success) {
        $message.success("操作成功！")
        emit("success", res.result)
        closeModal();
      } else {
        $message.error(res.message)
      }
    })
  } catch (e) {
    console.log(e);
  } finally {
    // setModalProps({confirmLoading: false});
  }
}

</script>
<style lang="less" scoped>
  td {
    height: 35px;
  }
</style>